﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.Xpo;

namespace POI.eTransmittal.Enitity
{
    [OptimisticLocking(false),DeferredDeletion(false)]
   public  class Contact:XPCustomObject
    {
        [Key(true)]
        public int ID;
   
       public string Name;
     
       public bool Internal;
       public string Fax;
       public string OthersInfo;
       [Association("Contact_Info")]
       public XPCollection<ContactInfo> ContactsInfo
       {
           get
           {
               return GetCollection<ContactInfo>("ContactsInfo");
           }
       }
       public Contact()
       {
       }
       public Contact(Session session):base(session)
       {
       }
     
       public ContactInfo AddFaxNo(string fax)
       {
           if (!IsFaxExist(fax))
           {
               ContactInfo ci = new ContactInfo(Session);
               ci.Type = ContactInfo.FAX;
               ci.Value = fax;
               ci.Contact = this;

               ContactsInfo.Add(ci);
               ci.Save();
               return ci;
           }
           return null;
       }
       public bool IsFaxExist(string fax)
       {
           foreach (ContactInfo info in ContactsInfo)
           {
               if (info.Type == ContactInfo.FAX)
               {
                   if (string.Equals(fax.Trim(), info.Value.Trim(), StringComparison.CurrentCultureIgnoreCase))
                   {
                       return true;
                   }
               }
           }
           return false;
       }

    }
}
